﻿namespace Chain.IDAL
{
    using Chain.DBUtility;
    using Chain.Model;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Runtime.InteropServices;
    using System.Text;

    public class SysShop
    {
        public int Add(Chain.Model.SysShop model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into SysShop(");
            builder.Append("ShopName,ShopTelephone,ShopContactMan,ShopAreaID,ShopAddress,ShopRemark,ShopCreateTime,ShopState,ShopPrintTitle,ShopPrintFoot,ShopSmsName,SettlementInterval,ShopProportion,IsAllianceProgram,FatherShopID,PointCount,SmsCount,PointType,SmsType)");
            builder.Append(" values (");
            builder.Append("@ShopName,@ShopTelephone,@ShopContactMan,@ShopAreaID,@ShopAddress,@ShopRemark,@ShopCreateTime,@ShopState,@ShopPrintTitle,@ShopPrintFoot,@ShopSmsName,@SettlementInterval,@ShopProportion,@IsAllianceProgram,@FatherShopID,@PointCount,@SmsCount,@PointType,@SmsType)");
            builder.Append(";select @@IDENTITY");
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@ShopName", SqlDbType.NVarChar, 100), new SqlParameter("@ShopTelephone", SqlDbType.VarChar, 50), new SqlParameter("@ShopContactMan", SqlDbType.NVarChar, 50), new SqlParameter("@ShopAreaID", SqlDbType.Int, 4), new SqlParameter("@ShopAddress", SqlDbType.NVarChar, 500), new SqlParameter("@ShopRemark", SqlDbType.NVarChar, 500), new SqlParameter("@ShopCreateTime", SqlDbType.DateTime), new SqlParameter("@ShopState", SqlDbType.Bit, 1), new SqlParameter("@ShopPrintTitle", SqlDbType.NVarChar, 500), new SqlParameter("@ShopPrintFoot", SqlDbType.NVarChar, 500), new SqlParameter("@ShopSmsName", SqlDbType.NVarChar, 500), new SqlParameter("@SettlementInterval", SqlDbType.Int, 4), new SqlParameter("@ShopProportion", SqlDbType.Money, 8), new SqlParameter("@IsAllianceProgram", SqlDbType.Bit, 1), new SqlParameter("@FatherShopID", SqlDbType.Int, 4), new SqlParameter("@PointCount", SqlDbType.Int, 4), 
                new SqlParameter("@SmsCount", SqlDbType.Int, 4), new SqlParameter("@PointType", SqlDbType.Int, 4), new SqlParameter("@SmsType", SqlDbType.Int, 4)
             };
            cmdParms[0].Value = model.ShopName;
            cmdParms[1].Value = model.ShopTelephone;
            cmdParms[2].Value = model.ShopContactMan;
            cmdParms[3].Value = model.ShopAreaID;
            cmdParms[4].Value = model.ShopAddress;
            cmdParms[5].Value = model.ShopRemark;
            cmdParms[6].Value = model.ShopCreateTime;
            cmdParms[7].Value = model.ShopState;
            cmdParms[8].Value = model.ShopPrintTitle;
            cmdParms[9].Value = model.ShopPrintFoot;
            cmdParms[10].Value = model.ShopSmsName;
            cmdParms[11].Value = model.SettlementInterval;
            cmdParms[12].Value = model.ShopProportion;
            cmdParms[13].Value = model.IsAllianceProgram;
            cmdParms[14].Value = model.FatherShopID;
            cmdParms[15].Value = model.PointCount;
            cmdParms[0x10].Value = model.SmsCount;
            cmdParms[0x11].Value = model.PointType;
            cmdParms[0x12].Value = model.SmsType;
            object single = DbHelperSQL.GetSingle(builder.ToString(), cmdParms);
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }

        public Chain.Model.SysShop DataRowToModel(DataRow row)
        {
            Chain.Model.SysShop shop = new Chain.Model.SysShop();
            if (row != null)
            {
                if ((row["ShopID"] != null) && (row["ShopID"].ToString() != ""))
                {
                    shop.ShopID = int.Parse(row["ShopID"].ToString());
                }
                if (row["ShopName"] != null)
                {
                    shop.ShopName = row["ShopName"].ToString();
                }
                if (row["ShopTelephone"] != null)
                {
                    shop.ShopTelephone = row["ShopTelephone"].ToString();
                }
                if (row["ShopContactMan"] != null)
                {
                    shop.ShopContactMan = row["ShopContactMan"].ToString();
                }
                if ((row["ShopAreaID"] != null) && (row["ShopAreaID"].ToString() != ""))
                {
                    shop.ShopAreaID = int.Parse(row["ShopAreaID"].ToString());
                }
                if (row["ShopAddress"] != null)
                {
                    shop.ShopAddress = row["ShopAddress"].ToString();
                }
                if (row["ShopRemark"] != null)
                {
                    shop.ShopRemark = row["ShopRemark"].ToString();
                }
                if ((row["ShopCreateTime"] != null) && (row["ShopCreateTime"].ToString() != ""))
                {
                    shop.ShopCreateTime = DateTime.Parse(row["ShopCreateTime"].ToString());
                }
                if ((row["ShopState"] != null) && (row["ShopState"].ToString() != ""))
                {
                    if ((row["ShopState"].ToString() == "1") || (row["ShopState"].ToString().ToLower() == "true"))
                    {
                        shop.ShopState = true;
                    }
                    else
                    {
                        shop.ShopState = false;
                    }
                }
                if (row["ShopPrintTitle"] != null)
                {
                    shop.ShopPrintTitle = row["ShopPrintTitle"].ToString();
                }
                if (row["ShopPrintFoot"] != null)
                {
                    shop.ShopPrintFoot = row["ShopPrintFoot"].ToString();
                }
                if (row["ShopSmsName"] != null)
                {
                    shop.ShopSmsName = row["ShopSmsName"].ToString();
                }
            }
            return shop;
        }

        public bool Delete(int ShopID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from SysShop ");
            builder.Append(" where ShopID=@ShopID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@ShopID", SqlDbType.Int, 4) };
            cmdParms[0].Value = ShopID;
            return (DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms) > 0);
        }

        public bool DeleteList(string ShopIDlist)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from SysShop ");
            builder.Append(" where ShopID in (" + ShopIDlist + ")  ");
            return (DbHelperSQL.ExecuteSql(builder.ToString()) > 0);
        }

        public bool Exists(int ShopID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select count(1) from SysShop");
            builder.Append(" where ShopID=@ShopID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@ShopID", SqlDbType.Int, 4) };
            cmdParms[0].Value = ShopID;
            return DbHelperSQL.Exists(builder.ToString(), cmdParms);
        }

        public bool Exists(string shopName)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select count(1) from SysShop");
            builder.Append(" where ShopName=@ShopName");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@ShopName", SqlDbType.NVarChar, 100) };
            cmdParms[0].Value = shopName;
            return DbHelperSQL.Exists(builder.ToString(), cmdParms);
        }

        public bool Exists(string shopName, int shopID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select count(1) from SysShop");
            builder.Append(" where ShopName = @ShopName and ShopID<>@ShopID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@ShopName", SqlDbType.VarChar, 50), new SqlParameter("@ShopID", SqlDbType.Int) };
            cmdParms[0].Value = shopName;
            cmdParms[1].Value = shopID;
            return DbHelperSQL.Exists(builder.ToString(), cmdParms);
        }

        public DataSet GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select ShopID,ShopName,ShopTelephone,ShopContactMan,ShopAreaID,ShopAddress,ShopRemark,ShopCreateTime,ShopState,ShopPrintTitle,ShopPrintFoot,ShopSmsName,SettlementInterval,ShopProportion,IsAllianceProgram,FatherShopID,PointCount,SmsCount,PointType,SmsType ");
            builder.Append(" FROM SysShop ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select ");
            if (Top > 0)
            {
                builder.Append(" top " + Top.ToString());
            }
            builder.Append(" ShopID,ShopName,ShopTelephone,ShopContactMan,ShopAreaID,ShopAddress,ShopRemark,ShopCreateTime,ShopState,ShopPrintTitle,ShopPrintFoot,ShopSmsName,SettlementInterval,ShopProportion,IsAllianceProgram,FatherShopID,PointCount,SmsCount,PointType,SmsType  ");
            builder.Append(" FROM SysShop ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("SELECT * FROM ( ");
            builder.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                builder.Append("order by T." + orderby);
            }
            else
            {
                builder.Append("order by T.ShopID desc");
            }
            builder.Append(")AS Row, T.*  from SysShop T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                builder.Append(" WHERE " + strWhere);
            }
            builder.Append(" ) TT");
            builder.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(builder.ToString());
        }

        public DataSet GetListS(int PageSize, int PageIndex, string[] strWhere, out int resCount)
        {
            string tableName = "SysShop";
            string[] column = new string[] { "*" };
            string[] condition = strWhere;
            int recordCount = 1;
            DataSet set = DbHelperSQL.GetTable(tableName, column, condition, "ShopID", true, PageSize, PageIndex, recordCount);
            resCount = int.Parse(set.Tables[1].Rows[0][0].ToString());
            return set;
        }

        public DataSet GetListSP(int PageSize, int PageIndex, string[] strWhere, out int resCount)
        {
            string tableName = "SysShop";
            string[] column = new string[] { "*" };
            string[] condition = strWhere;
            int recordCount = 1;
            DataSet set = DbHelperSQL.GetTable(tableName, column, condition, "ShopID", true, PageSize, PageIndex, recordCount);
            resCount = int.Parse(set.Tables[1].Rows[0][0].ToString());
            return set;
        }

        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("ShopID", "SysShop");
        }

        public Chain.Model.SysShop GetModel(int ShopID)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select  top 1 ShopID,ShopName,ShopTelephone,ShopContactMan,ShopAreaID,ShopAddress,ShopRemark,ShopCreateTime,ShopState,ShopPrintTitle,ShopPrintFoot,ShopSmsName,SettlementInterval,ShopProportion,IsAllianceProgram,FatherShopID,PointCount,SmsCount,PointType,SmsType from SysShop ");
            builder.Append(" where ShopID=@ShopID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@ShopID", SqlDbType.Int, 4) };
            cmdParms[0].Value = ShopID;
            Chain.Model.SysShop shop = new Chain.Model.SysShop();
            DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms);
            if (set.Tables[0].Rows.Count <= 0)
            {
                return null;
            }
            if ((set.Tables[0].Rows[0]["ShopID"] != null) && (set.Tables[0].Rows[0]["ShopID"].ToString() != ""))
            {
                shop.ShopID = int.Parse(set.Tables[0].Rows[0]["ShopID"].ToString());
            }
            if ((set.Tables[0].Rows[0]["ShopName"] != null) && (set.Tables[0].Rows[0]["ShopName"].ToString() != ""))
            {
                shop.ShopName = set.Tables[0].Rows[0]["ShopName"].ToString();
            }
            if ((set.Tables[0].Rows[0]["ShopTelephone"] != null) && (set.Tables[0].Rows[0]["ShopTelephone"].ToString() != ""))
            {
                shop.ShopTelephone = set.Tables[0].Rows[0]["ShopTelephone"].ToString();
            }
            if ((set.Tables[0].Rows[0]["ShopContactMan"] != null) && (set.Tables[0].Rows[0]["ShopContactMan"].ToString() != ""))
            {
                shop.ShopContactMan = set.Tables[0].Rows[0]["ShopContactMan"].ToString();
            }
            if ((set.Tables[0].Rows[0]["ShopAreaID"] != null) && (set.Tables[0].Rows[0]["ShopAreaID"].ToString() != ""))
            {
                shop.ShopAreaID = int.Parse(set.Tables[0].Rows[0]["ShopAreaID"].ToString());
            }
            if ((set.Tables[0].Rows[0]["ShopAddress"] != null) && (set.Tables[0].Rows[0]["ShopAddress"].ToString() != ""))
            {
                shop.ShopAddress = set.Tables[0].Rows[0]["ShopAddress"].ToString();
            }
            if ((set.Tables[0].Rows[0]["ShopRemark"] != null) && (set.Tables[0].Rows[0]["ShopRemark"].ToString() != ""))
            {
                shop.ShopRemark = set.Tables[0].Rows[0]["ShopRemark"].ToString();
            }
            if ((set.Tables[0].Rows[0]["ShopCreateTime"] != null) && (set.Tables[0].Rows[0]["ShopCreateTime"].ToString() != ""))
            {
                shop.ShopCreateTime = DateTime.Parse(set.Tables[0].Rows[0]["ShopCreateTime"].ToString());
            }
            if ((set.Tables[0].Rows[0]["ShopState"] != null) && (set.Tables[0].Rows[0]["ShopState"].ToString() != ""))
            {
                if ((set.Tables[0].Rows[0]["ShopState"].ToString() == "1") || (set.Tables[0].Rows[0]["ShopState"].ToString().ToLower() == "true"))
                {
                    shop.ShopState = true;
                }
                else
                {
                    shop.ShopState = false;
                }
            }
            if ((set.Tables[0].Rows[0]["ShopPrintTitle"] != null) && (set.Tables[0].Rows[0]["ShopPrintTitle"].ToString() != ""))
            {
                shop.ShopPrintTitle = set.Tables[0].Rows[0]["ShopPrintTitle"].ToString();
            }
            if ((set.Tables[0].Rows[0]["ShopPrintFoot"] != null) && (set.Tables[0].Rows[0]["ShopPrintFoot"].ToString() != ""))
            {
                shop.ShopPrintFoot = set.Tables[0].Rows[0]["ShopPrintFoot"].ToString();
            }
            if ((set.Tables[0].Rows[0]["ShopSmsName"] != null) && (set.Tables[0].Rows[0]["ShopSmsName"].ToString() != ""))
            {
                shop.ShopSmsName = set.Tables[0].Rows[0]["ShopSmsName"].ToString();
            }
            if ((set.Tables[0].Rows[0]["SettlementInterval"] != null) && (set.Tables[0].Rows[0]["SettlementInterval"].ToString() != ""))
            {
                shop.SettlementInterval = int.Parse(set.Tables[0].Rows[0]["SettlementInterval"].ToString());
            }
            if ((set.Tables[0].Rows[0]["ShopProportion"] != null) && (set.Tables[0].Rows[0]["ShopProportion"].ToString() != ""))
            {
                shop.ShopProportion = decimal.Parse(set.Tables[0].Rows[0]["ShopProportion"].ToString());
            }
            if ((set.Tables[0].Rows[0]["IsAllianceProgram"] != null) && (set.Tables[0].Rows[0]["IsAllianceProgram"].ToString() != ""))
            {
                if ((set.Tables[0].Rows[0]["IsAllianceProgram"].ToString() == "1") || (set.Tables[0].Rows[0]["IsAllianceProgram"].ToString().ToLower() == "true"))
                {
                    shop.IsAllianceProgram = true;
                }
                else
                {
                    shop.IsAllianceProgram = false;
                }
            }
            if ((set.Tables[0].Rows[0]["FatherShopID"] != null) && (set.Tables[0].Rows[0]["FatherShopID"].ToString() != ""))
            {
                shop.FatherShopID = int.Parse(set.Tables[0].Rows[0]["FatherShopID"].ToString());
            }
            if ((set.Tables[0].Rows[0]["PointCount"] != null) && (set.Tables[0].Rows[0]["PointCount"].ToString() != ""))
            {
                shop.PointCount = Convert.ToInt32(set.Tables[0].Rows[0]["PointCount"]);
            }
            if ((set.Tables[0].Rows[0]["SmsCount"] != null) && (set.Tables[0].Rows[0]["SmsCount"].ToString() != ""))
            {
                shop.SmsCount = Convert.ToInt32(set.Tables[0].Rows[0]["SmsCount"]);
            }
            if ((set.Tables[0].Rows[0]["PointType"] != null) && (set.Tables[0].Rows[0]["PointType"].ToString() != ""))
            {
                shop.PointType = Convert.ToInt32(set.Tables[0].Rows[0]["PointType"]);
            }
            if ((set.Tables[0].Rows[0]["SmsType"] != null) && (set.Tables[0].Rows[0]["SmsType"].ToString() != ""))
            {
                shop.SmsType = Convert.ToInt32(set.Tables[0].Rows[0]["SmsType"]);
            }
            return shop;
        }

        public int GetRecordCount(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select count(1) FROM SysShop ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            object single = DbHelperSQL.GetSingle(builder.ToString());
            if (single == null)
            {
                return 0;
            }
            return Convert.ToInt32(single);
        }

        public DataSet GetShop(params string[] strWhere)
        {
            string tableName = "V_RptShop";
            string[] column = new string[] { "*" };
            string[] condition = strWhere;
            return DbHelperSQL.GetTable(tableName, column, condition, "ShopID", true, 100, 1, 0);
        }

        public static DataSet GetShopTable(string[] column, string[] condition, string IndexColumn, bool IsAsc, string dtStartTime, string dtEndTime, int PageSize, int Page, int RecordCount)
        {
            string str = "";
            string inputSql = "";
            for (int i = 0; i < column.Length; i++)
            {
                str = str + column[i];
                if (i < (column.Length - 1))
                {
                    str = str + ",";
                }
            }
            if ((condition != null) && (condition.Length > 0))
            {
                for (int j = 0; j < condition.Length; j++)
                {
                    if (!(condition[j] == ""))
                    {
                        inputSql = inputSql + condition[j];
                        if (j < (condition.Length - 1))
                        {
                            inputSql = inputSql + " and ";
                        }
                    }
                }
            }
            inputSql = DbHelperSQL.ProcessSql(inputSql);
            SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@ReturnFields", SqlDbType.VarChar, 500), new SqlParameter("@OrderFields", SqlDbType.VarChar, 0xff), new SqlParameter("@PKField", SqlDbType.VarChar, 0xff), new SqlParameter("@IsDesc", SqlDbType.Bit), new SqlParameter("@Where", SqlDbType.VarChar, 0x3e8), new SqlParameter("@StartTime", SqlDbType.VarChar, 50), new SqlParameter("@EndTime", SqlDbType.VarChar, 50), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@PageIndex", SqlDbType.Int) };
            parameter[0].Value = str;
            parameter[1].Value = IndexColumn;
            parameter[2].Value = IndexColumn;
            parameter[3].Value = IsAsc ? 0 : 1;
            parameter[4].Value = inputSql;
            parameter[5].Value = dtStartTime;
            parameter[6].Value = dtEndTime;
            parameter[7].Value = PageSize;
            parameter[8].Value = Page;
            return DbHelperSQL.ExecuteProcedure("CP_ShopTotal", parameter);
        }

        public DataSet GetTotalRptData(string memWhere, string rechargeWhere, string orderWhere, string countWhere, string memstoragetimingWhere, string drawmoneyWhere)
        {
            string sQLString = string.Format("select LevelID,(select count(MemID) from Mem where Mem.MemLevelID = MemLevel.LevelID and MemID>0 and {0})as MemNumber from MemLevel", memWhere);
            string str2 = string.Format("SELECT Sum(RechargeMoney-RechargeGive),Sum(RechargeGive),RechargeType FROM MemRecharge where {0} group by RechargeType", rechargeWhere);
            string str3 = string.Format("select CAST(OrderTotalMoney AS numeric(20,2)) AS OrderTotalMoney ,OrderDiscountMoney,OrderPayCoupon,OrderPayType,OrderPayCard,OrderPayCash,OrderPayBink from OrderLog  where {0} ", orderWhere);
            string str4 = string.Format(" select CAST(CountTotalMoney AS numeric(20,2)) AS CountTotalMoney ,CountDiscountMoney,CountPayCoupon,CountPayType,CountPayCard,CountPayCash,CountPayBink from MemCount  where {0} ", countWhere);
            string str5 = string.Format("SELECT ISNULL(SUM(StorageTimingDiscountMoney),0) AS StorageTimingDiscountMoney, ISNULL(SUM(StorageTimingPayCard),0) AS StorageTimingPayCard,ISNULL(SUM(StorageTimingPayCash),0) AS StorageTimingPayCash,\r\n                                                          ISNULL(SUM(StorageTimingPayBink),0) AS StorageTimingPayBink,ISNULL(SUM(StorageTimingPayCoupon),0) AS StorageTimingPayCoupon FROM MemStorageTiming WHERE {0}", memstoragetimingWhere);
            string str6 = string.Format("SELECT ISNULL(SUM(DrawMoney),0) as AllDrawMoney, ISNULL(SUM(DrawActualMoney),0) AS AllDrawActualMoney FROM MemDrawMoney where {0}", drawmoneyWhere);
            DataTable table = DbHelperSQL.Query(sQLString).Tables[0];
            DataTable table2 = DbHelperSQL.Query(str2).Tables[0];
            DataTable table3 = DbHelperSQL.Query(str3).Tables[0];
            DataTable table4 = DbHelperSQL.Query(str4).Tables[0];
            DataTable table5 = DbHelperSQL.Query(str5).Tables[0];
            DataTable table6 = DbHelperSQL.Query(str6).Tables[0];
            table.TableName = "dtMem";
            table2.TableName = "dtRecharge";
            table3.TableName = "dtOrder";
            table4.TableName = "dtCount";
            table5.TableName = "dtmemstoragetiming";
            table6.TableName = "dtdrawmoney";
            DataSet set = new DataSet();
            set.Tables.Add(table.Copy());
            set.Tables.Add(table2.Copy());
            set.Tables.Add(table3.Copy());
            set.Tables.Add(table4.Copy());
            set.Tables.Add(table5.Copy());
            set.Tables.Add(table6.Copy());
            return set;
        }

        public DataSet getTotalShop(string dtStartTime, string dtEndTime, params string[] strWhere)
        {
            string[] column = new string[] { "*" };
            string[] condition = strWhere;
            return GetShopTable(column, condition, "ShopID", true, dtStartTime, dtEndTime, 100, 1, 0);
        }

        public int Update(Chain.Model.SysShop model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update SysShop set ");
            builder.Append("ShopName=@ShopName,");
            builder.Append("ShopTelephone=@ShopTelephone,");
            builder.Append("ShopContactMan=@ShopContactMan,");
            builder.Append("ShopAreaID=@ShopAreaID,");
            builder.Append("ShopAddress=@ShopAddress,");
            builder.Append("ShopRemark=@ShopRemark,");
            builder.Append("ShopState=@ShopState,");
            builder.Append("ShopPrintTitle=@ShopPrintTitle,");
            builder.Append("ShopPrintFoot=@ShopPrintFoot,");
            builder.Append("ShopSmsName=@ShopSmsName,");
            builder.Append("SettlementInterval=@SettlementInterval,");
            builder.Append("ShopProportion=@ShopProportion,");
            builder.Append("PointCount=@PointCount,");
            builder.Append("SmsCount=@SmsCount,");
            builder.Append("PointType=@PointType,");
            builder.Append("SmsType=@SmsType");
            builder.Append(" where ShopID=@ShopID");
            SqlParameter[] cmdParms = new SqlParameter[] { 
                new SqlParameter("@ShopName", SqlDbType.NVarChar, 100), new SqlParameter("@ShopTelephone", SqlDbType.VarChar, 50), new SqlParameter("@ShopContactMan", SqlDbType.NVarChar, 50), new SqlParameter("@ShopAreaID", SqlDbType.Int, 4), new SqlParameter("@ShopAddress", SqlDbType.NVarChar, 500), new SqlParameter("@ShopRemark", SqlDbType.NVarChar, 500), new SqlParameter("@ShopState", SqlDbType.Bit, 1), new SqlParameter("@ShopPrintTitle", SqlDbType.NVarChar, 500), new SqlParameter("@ShopPrintFoot", SqlDbType.NVarChar, 500), new SqlParameter("@ShopSmsName", SqlDbType.NVarChar, 500), new SqlParameter("@SettlementInterval", SqlDbType.Int, 4), new SqlParameter("@ShopProportion", SqlDbType.Money, 8), new SqlParameter("@PointCount", SqlDbType.Int, 4), new SqlParameter("@SmsCount", SqlDbType.Int, 4), new SqlParameter("@PointType", SqlDbType.Int, 4), new SqlParameter("@SmsType", SqlDbType.Int, 4), 
                new SqlParameter("@ShopID", SqlDbType.Int, 4)
             };
            cmdParms[0].Value = model.ShopName;
            cmdParms[1].Value = model.ShopTelephone;
            cmdParms[2].Value = model.ShopContactMan;
            cmdParms[3].Value = model.ShopAreaID;
            cmdParms[4].Value = model.ShopAddress;
            cmdParms[5].Value = model.ShopRemark;
            cmdParms[6].Value = model.ShopState;
            cmdParms[7].Value = model.ShopPrintTitle;
            cmdParms[8].Value = model.ShopPrintFoot;
            cmdParms[9].Value = model.ShopSmsName;
            cmdParms[10].Value = model.SettlementInterval;
            cmdParms[11].Value = model.ShopProportion;
            cmdParms[12].Value = model.PointCount;
            cmdParms[13].Value = model.SmsCount;
            cmdParms[14].Value = model.PointType;
            cmdParms[15].Value = model.SmsType;
            cmdParms[0x10].Value = model.ShopID;
            if (DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms) > 0)
            {
                return 1;
            }
            return -3;
        }

        public int Update(int shopid, int smsType, int pointType)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update SysShop set ");
            builder.Append("PointType=@PointType,");
            builder.Append("SmsType=@SmsType");
            builder.Append(" where ShopID=@ShopID");
            SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@PointType", SqlDbType.Int, 4), new SqlParameter("@SmsType", SqlDbType.Int, 4), new SqlParameter("@ShopID", SqlDbType.Int, 4) };
            cmdParms[0].Value = pointType;
            cmdParms[1].Value = smsType;
            cmdParms[2].Value = shopid;
            if (DbHelperSQL.ExecuteSql(builder.ToString(), cmdParms) > 0)
            {
                return 1;
            }
            return -3;
        }
    }
}

